$(function(){
    Ext.onReady(function() {
        var obj = {
            account: '',
            init: function () {
                var that = this;
                that.account = localStorage.getItem('account') || '';
                if(!that.account){
                    Ext.MessageBox.alert('温馨提示', '账户信息过期，请重新登录！');
                    window.location.replace('./login.html');
                    return;
                }
                // demo数据开始，下方可删除
                var columns = [
                    {
                        "applicant": '13500000001',
                        "id" : "2",
                        "phone" : "15857502013",
                        "lxr" : "冯翔",
                        "fl" : "带薪年假、生日补贴、免费体检",
                        "address" : "华宇路108号",
                        "gw" : "保安",
                        "zprs" : "10",
                        "xc" : "4000",
                        "xs" : "绍兴县",
                        "xzjd" : "柯桥街道",
                        "zpyq" : "30-50，身体健康",
                        "zpdw" : "绿城物业",
                    }, {
                        "applicant": '13500000002',
                        "id" : "1",
                        "phone" : "15857502013",
                        "lxr" : "冯翔",
                        "fl" : "带薪年假、生日补贴、免费体检",
                        "address" : "华宇路108号",
                        "gw" : "门卫",
                        "zprs" : "10",
                        "xc" : "2000",
                        "xs" : "绍兴县",
                        "xzjd" : "柯桥街道",
                        "zpyq" : "30-50，身体健康",
                        "zpdw" : "绿城物业",
                    }, {
                        "applicant": '13500000003',
                        "id" : "3",
                        "phone" : "15857502013",
                        "lxr" : "冯翔",
                        "fl" : "带薪年假、生日补贴、免费体检",
                        "address" : "昆仑大厦",
                        "gw" : "业务员",
                        "zprs" : "3",
                        "xc" : "600",
                        "xs" : "越城区",
                        "xzjd" : "迪荡街道",
                        "zpyq" : "30-50，身体健康",
                        "zpdw" : "贝壳房产",
                    }
                ];
                that.initExtList() // 不传参数 请求接口
            },
            initExtList: function (data) {
                var store = Ext.create("Ext.data.Store",{
                    fields: ['applicant','id', 'phone','lxr','fl','address','gw','zprs','xc','xs','xzjd','zpyq','zpdw'],
                    data:data
                });
                if(!data){
                    // 接口请求
                    store = Ext.create("Ext.data.Store", {
                        fields: ['applicant','id', 'phone','lxr','fl','address','gw','zprs','xc','xs','xzjd','zpyq','zpdw'],
                        autoLoad: true,
                        pageSize: 20, // 一页 20条
                        proxy: {
                            type: 'ajax',
                            url: $.getAjaxHost('def') + 'zpinfo/applicantList',
                            params: {
                                account: localStorage.getItem('account')
                            },
                            // page 第几页 1
                            // start 开始页 0开始
                            // limit 页面大小
                            reader: {
                                type: 'json',
                                root: 'list',
                                totalProperty: 'total' // 总数对应字段名称
                            }
                        }
                    });
                }

                var grid = new Ext.grid.GridPanel({
                    renderTo: document.body,
                    title: '应聘人员信息列表',
                    width: '100%',
                    height: '100vh',
                    autoHeight : true,
                    stripeRows: true,
                    loadMask:true,
                    autoExpandColumn: 'id',
                    stateful: true,
                    stateId: 'grid',
                    layout: 'fit',
                    fullscreen: true,
                    columns: [
                        { text: '编号', dataIndex: 'id', width: 50,sortable : true },
                        { text: '应聘人员电话', dataIndex: 'applicant', width: 120,sortable : false },
                        { text: '应聘公司', dataIndex: 'zpdw', width: 120,sortable : true },
                        { text: '应聘岗位', dataIndex: 'gw', width: 150,sortable : true },
                        { text: '应聘区域', dataIndex: 'xs', width: 80,sortable : true },
                        { text: '应聘街道', dataIndex: 'xzjd', width: 120,sortable : true },
                        { text: '应聘地址', dataIndex: 'address', width: 120,sortable : true },
                        { text: '岗位待遇（元/月）', dataIndex: 'xc', width: 150,sortable : true },
                        { text: '招聘人数', dataIndex: 'zprs', width: 150,sortable : true },
                        { text: '应聘要求', dataIndex: 'zpyq', width: 250,sortable : false,hidden: true},
                        { text: '应聘福利', dataIndex: 'fl', width: 250,sortable : false,hidden: true},
                        { text: '联系人姓名', dataIndex: 'lxr', width: 150,sortable : false,hidden: true},
                        { text: '联系人电话', dataIndex: 'phone', width: 120,sortable : false,hidden: true}

                    ],
                    store: store,
                    bbar : {
                        xtype : 'pagingtoolbar',
                        store: store,
                        pageSize: 20,
                        displayInfo: true,
                        displayMsg: '显示 {0} - {1} 条，共计 {2} 条',
                        emptyMsg: "没有数据"
                    }

                });
            }
        };
        obj.init();
    });
});